<?php
namespace app\common\lib\task;

use app\common\lib\Redis;
use app\common\lib\redis\Predis;
use app\common\lib\Sms;

/**
 * 在这个类中执行分配的task任务
 * Class Task
 * @package app\common\lib\task
 */
class Task
{
    //发送手机验证码
    public function send_sms($data,$serv)
    {
        try{
            $response = Sms::sendSms($data['phone'],$data['code']);
        }catch(\Exception $e){
            echo $e->getMessage();
        }
        //将手机号以及验证码放置到redis中
        if($response->Message == 'OK') {
            Predis::getInstance()->set(Redis::smsKey($data['phone']),$data['code'],config('redis.time'));
        }else{
            return false;
        }
        print_r($response);
        return 'on task finish';
    }
    //推送直播信息
    public function push_live($data,$ser)
    {
//        $redis = Predis::getInstance()->sMembers(config('redis.redis_game_key'));
//        if(!empty($redis)){
            foreach($ser->ports[0]->connections  as $fd){
                if($ser->exist($fd)){
//                    print_r($fd.PHP_EOL);
                    $ser->push($fd,json_encode($data));
                }
            }
//        }
    }
}